<template>
	<!-- 页面内容--金额选择页面1 -->
	<view style="width: 100vw; min-height: 100vh;background-color: #1F2022; color: #fff;">
		<formheadVue headname="NeoLoan " :pagenum='5' :emptyleft='true'></formheadVue>
		<view class="P-head">
			<view class="P-1 flexcenter">
				<view class="P-1-head">
					<view class="flexcenter">
						<p style="margin-left: 20rpx;">{{$t('money.Loanamount')}}</p>
					</view>
					<view class="l-1">
						<uni-data-select :emptyTips="$t('emptyTips')" :clear="false" v-model="getmoney"
							:localdata="getmoneyrange" @change="getmoneyrangeChange"
							:placeholder="$t('pleaseselect')"></uni-data-select>
					</view>
					<view class="l-3">
						<image src="../../static/progressing.png" mode=""></image>
					</view>
					<view class="l-4 flexrowspacebetween">
						<p>฿ 1,000</p>
						<p>฿ 50,000</p>
					</view>
					<view class="l-5">
						<view class="flexrowspacearound l-5-1">
							<view class="locked">฿ 10,000
								<view class="l-5-1-img flexcenter">
									<image src="../../static/lockedsicon.png" mode=""></image>
								</view>
							</view>
							<view class="locked">฿ 15,000
								<view class="l-5-1-img flexcenter">
									<image src="../../static/lockedsicon.png" mode=""></image>
								</view>
							</view>
						</view>
						<view class="flexrowspacearound l-5-2">
							<p>{{$t('money.lockedloantime')}} 1</p>
							<p>{{$t('money.lockedloantime')}} 2</p>
						</view>
					</view>
				</view>
			</view>
			<view class="P-2">
				{{$t('money.Loanperiod')}}
			</view>

			<view class="P-4 flexrowspacebetween">
				<view class="P-4-1">
					91 {{$t('money.day')}}
					<view class="l-5-1-img flexcenter" style="
					background-image: url('../../static/unlockedsicon.png');
					background-size: 100% 100%;
					background-repeat: no-repeat;
					background-color: transparent;
					">

					</view>
				</view>
				<view class="P-4-2">
					182 {{$t('money.day')}}
					<view class="l-5-1-img flexcenter">
						<image src="../../static/lockedsicon.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="P-5">
				<view class="P-5-l  P-5-l-bright flexrowspacebetween">
					<P>{{$t('money.Paymentdate')}}</P>
					<P class="text">{{repayDate}}</P>
				</view>
				<view style="margin-top: 10rpx;" class="P-5-l P-5-l-bright flexrowspacebetween">
					<P>{{$t('money.Repaymentamount')}}</P>
					<P class="text">฿ {{formatAmount(getmoney+rateValue)}}</P>
				</view>
				<view class="P-5-l flexrowspacebetween">
					<P>{{$t('money.Loanamount')}}</P>
					<P class="text">฿ {{formatAmount(getmoney)}}</P>
				</view>
				<view class="P-5-l flexrowspacebetween">
					<P>{{$t('money.interest')}}</P>
					<P class="text"> + ฿ {{formatAmount(rateValue)}}</P>
				</view>
				<view class="P-5-l P-5-l-bright flexrowspacebetween">
					<P>{{$t('money.receiveamount')}}</P>
					<P class="text">฿ {{formatAmount(getmoney)}}</P>
				</view>
			</view>
			<view class="P-6">
				<view class="flexrowstart">
					<image src="../../static/bankicon.png" mode=""></image>
					<p class="title">{{$t('money.bankcardnum')}}</p>
				</view>
				<view class="input">
					<p>{{bankNumer}}</p>
				</view>

			</view>

			<view v-if="canclick" @click="fn1()" class="P-3 flexcenter">
				<p>{{$t('index.confirm')}}</p>
			</view>
			<view v-else class="P-3 flexcenter">
				<p style="background-color: #D9D9D9;">{{$t('index.confirm')}}</p>
			</view>

		</view>
	</view>
</template>

<script>
	import formheadVue from '../../components/formhead.vue';
	import {
		encryptAES
	} from '@/pages/utils/CryptoJS.js';
	import api from '@/pages/utils/api.js';
	import setDot from '@/pages/utils/setdot.js';
	export default {
		data() {
			return {
				productIdValue: '', //产品id
				detailIdValue: '', //产品详情id
				maximumMoney: 0,
				minimumMoney: 0,
				moneyStep: 0,
				canclick: false,
				bankNumer: 0,
				getmoney: 1000,
				getmoneyrange: [],

				repayDate: '',
				rateValue: '',

			}
		},
		components: {
			formheadVue
		},
		onBackPress(options) {
			if (options.from === 'navigateBack') {
				return false;
			}
			return true;
		},
		onShow() {
			let params = {
				vjeu: '1'
			}
			api.getBankInfo(params).then(res => {
				console.log('获取银行卡', res);
				const data = res[0]
				if (data) {
					this.$nextTick(() => {
						this.bankNumer = data.yxsl || ''
					})
				}
			})

		},
		created() {
			this.repayDate = this.getDateAfter90Days()
			this.getqueryProductData()
		},
		methods: {
			SetdotFun(type) {
				switch (type) {
					case 'chooosemoney':
						if (uni.getStorageSync('hasloanstatus')) {
							//复
							setDot('CLICK_AMOUNT_SUBMIT')
						} else {
							//首
							setDot('CLICK_FIRST_AMOUNT_SUBMIT')

						}
						break;
					case 'presbumit':
						if (uni.getStorageSync('hasloanstatus')) {
							//复
							setDot('CLICK_CONFITM_SUBMIT')
						} else {
							//首
							setDot('CLICK_FIRST_CONFITM_SUBMIT')

						}
						break;
					default:
						break;
				}

			},
			getmoneyrangeChange(e) {
				console.log('金额选择发生了变化', e);
				console.log('getMoney当前选择的金额', this.getmoney);
				this.SetdotFun('chooosemoney')
				this.rateValue = this.getmoney * 0.0003 * 91
			},
			formatAmount(amount) {
				const number = parseFloat(amount);
				if (isNaN(number)) return '0';
				const isInteger = Number.isInteger(number);

				// 格式化为字符串，并添加千位分隔符
				const parts = number
					.toFixed(isInteger ? 0 : 2)
					.split('.');

				parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');

				return parts.join('.');
			},
			getqueryProductData() {
				api.getqueryProduct()
					.then((data) => {
						console.log('产品详情id查询', data);
						this.canclick = true;

						this.productIdValue = data.ding; // 产品ID
						this.detailIdValue = data.fdtp[0].hpvw;
						this.minimumMoney = Number(data.fdtp[0].mvto); // 最小金额
						this.maximumMoney = Number(data.fdtp[0].aemm); // 最大金额
						this.moneyStep = Number(data.fdtp[0].jwbu); // 步长
						const range = [];
						for (let val = this.maximumMoney; val >= this.minimumMoney; val -= this.moneyStep) {
							range.push({
								value: val,
								text: `฿ ${this.formatAmount(val)}`
							});
						}
						this.getmoney = Number(this.maximumMoney);
						this.SetdotFun('chooosemoney')
						this.rateValue = this.getmoney * 0.0003 * 91
						this.getmoneyrange = range;
						console.log('this.getmoneyrange', this.getmoneyrange);
						console.log('当前选择的金额', this.getmoney);

					})
					.catch((err) => {
						this.canclick = false;
						console.log('产品详情获取失败', err);
					});
			},
			getDateAfter90Days() {
				const today = new Date();
				// 增加 90 天
				today.setDate(today.getDate() + 90);

				const day = String(today.getDate()).padStart(2, '0');
				const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始
				const year = today.getFullYear();

				return `${day}-${month}-${year}`;
			},
			formatTime(seconds) {
				const h = String(Math.floor(seconds / 3600)).padStart(2, '0');
				const m = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0');
				const s = String(seconds % 60).padStart(2, '0');
				return `${h}:${m}:${s}`;
			},
			fn1() {
				console.log('可以预提交~', this.getmoney);
				if (!this.getmoney) {
					uni.showToast({
						icon: 'none',
						title: this.$t('money.Paytips')
					})
					return
				}
				api.getpreSubmitOrder({
						hpvw: this.detailIdValue,
						ding: this.productIdValue,
						mswl: this.getmoney,
					})
					.then((data) => {
						console.log('订单预提交成功拿到订单编号', data.jcno);
						uni.setStorageSync('currntOrderId',
							data.jcno
						)
						this.SetdotFun('presbumit')
						api.getContactsSetting({
							key: 'alternateContact',
						}).then(data => {
							console.log('检查有没有补充联系人', data);

							if (Number(data.alternateContact) > 0) {
								console.log('有补充联系人去补充联系人页面');
								uni.navigateTo({
									url: '/pages/demo11/demo11',
									animationType: 'slide-in-right',
									animationDuration: 200
								})
							} else {
								//直接进加载页面
								uni.reLaunch({
									url: '/pages/demo7/demo7'
								})
							}
						})
					})
					.catch((err) => {
						console.log('订单id获取失败', err);
					});

			}
		}
	}
</script>

<style lang="scss" scoped>
	.l-5-1-img {
		position: absolute;
		top: 10rpx;
		right: 10rpx;
		background-color: #57556D;
		border-radius: 50%;
		// padding: 4rpx;
		width: 40rpx;
		height: 40rpx;

		image {
			width: 36rpx;
			height: 36rpx;
		}
	}

	.P-6 {
		width: 100%;

		image {
			width: 56rpx;
			height: 44rpx;
		}

		.title {
			margin-left: 20rpx;
		}

		.input {
			margin-top: 20rpx;
			height: 100rpx;
			line-height: 100rpx;
			background-image: url('../../static/inputborder.png');
			background-size: 100% 100%;
			background-repeat: no-repeat;

			p {
				margin-left: 40rpx;
				color: #858585;
			}
		}
	}

	.P-5 {
		width: 100%;
		background-color: #393A3D;
		margin: 40rpx 0;
		padding-top: 90rpx;

		.P-5-l {
			.text {
				width: 300rpx;
				text-align: end;
			}

			color: #8A8A8A;
			padding:26rpx 30rpx;
		}

		.P-5-l-bright {
			background-color: #454649;
			color: #fff;
		}
	}

	.P-4 {
		width: 100%;

		.P-4-1,
		.P-4-2 {
			width: 49%;
			text-align: center;
			position: relative;
			padding: 36rpx 0;
			border-radius: 20rpx;
			font-size: 44rpx;
		}

		.P-4-1 {
			background-color: #BCA3F3;
			transition: all 0.2s;
			color: #000;
		}

		.P-4-2 {
			background-color: #342C42;
		}

		.P-4-1:active {
			transform: scale(0.96);
			box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.2);
		}

	}

	.P-2 {
		width: 100%;
		text-align: center;
		margin: 40rpx 0;
	}

	.P-word {
		margin-bottom: 40rpx;
	}

	.brightword {
		color: #CC9AF3;
		font-size: 60rpx;
	}

	.P-1 {
		margin-top: 14rpx;

		.P-1-head {
			width: 100%;
			height: fit-content;
			background-image: url('/static/bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 30rpx;
			margin: 0;
			color: #DDDDDD;
			padding-bottom: 180rpx;
			position: relative;

			.l-1 {
				margin: 40rpx 0 10rpx 0;
				background-image: url('/static/tipsbg.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 20rpx;
			}

			.l-2 {
				font-size: 60rpx;
				font-weight: bold;
			}

			.l-3 {
				image {
					width: 100%;
					height: 50rpx;
					margin: 20rpx 0rpx 0rpx 0rpx;
				}
			}

			.l-5 {
				width: 100%;
				background-color: #393A3D;
				border-radius: 0 0 30rpx 0rpx;
				height: 140rpx;
				padding: 20rpx;
				box-sizing: border-box;
				position: absolute;
				bottom: 0;
				left: 0;

				.brightword {
					color: #9680AB;
					margin: 0rpx 6rpx;
					font-size: 28rpx;
				}

				.l-5-2 {
					margin-top: 10rpx;

					p {
						width: 44%;
						text-align: center;
						font-size: 12px;
						color: #8A8A8A;
					}
				}

				.l-5-1 {

					.locked {
						background-color: #6B6283;
						padding: 10rpx 0rpx;
						font-weight: bold;

						width: 44%;
						text-align: center;
						border-radius: 10rpx;
						position: relative;

					}
				}

			}
		}

	}

	.P-head {
		width: 100%;
		background-color: #1F2022;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin-top: -110rpx;
	}




	.P-3 {
		width: 100%;
		margin: 40rpx 0rpx;

		p {
			width: 90%;
			height: 90rpx;
			background-color: #FFF584;
			text-align: center;
			color: #000;
			line-height: 90rpx;
			border-radius: 20rpx;
			font-size: 40rpx;
			box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.2);
			transition: all 0.2s;

		}

		p:active {
			transform: scale(0.96);
			box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.2);
		}

		@keyframes pulsebtn {
			0% {
				transform: scale(1);
			}

			50% {
				transform: scale(1.08);
			}

			100% {
				transform: scale(1);
			}
		}

	}


	.flexrowspacebetween {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.flexrowspacearound {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.flexrowstart {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.flexcenter {
		display: flex;
		justify-content: center;
		align-items: center;
		align-content: center;
	}
</style>